package edu.zut.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;

@WebServlet(name = "SessionServletDemo", value = "/session/demo")
public class SessionServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取session
        HttpSession session = request.getSession();
        //保存数据
        session.setAttribute("nowTime", LocalDateTime.now());
        //设置存活期  默认从浏览器打开---关闭
        session.setMaxInactiveInterval(24*60*60);
        //获取数据
        LocalDateTime time =(LocalDateTime) session.getAttribute("nowTime");
        System.out.println("time = " + time);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
